const router = require('koa-router')()
const {uploadOne} = require('../../middleware/uploadFile')
// 文章类型 ↓
router

// 上传文章类型图标
.post('/uploadArticleTypesIcon', uploadOne('/images/article-types-icon/'), async (ctx, next) => {
  let { host, post } = require('../../config/index').global
  ctx.body = {
    code: 0,
    message: '文章类型图标上传成功',
    data: {
      address: `http://${host}:${post}/images/article-types-icon/${ctx.req.file.filename}` 
    }
  }
})

// 上传文章图片
.post('/uploadArticleImage', uploadOne('/images/article-images/'), async (ctx, next) => {
  let { host, post } = require('../../config/index').global
  ctx.body = {
    code: 0,
    message: '文章图片上传成功',
    data: {
      address: `http://${host}:${post}/images/article-images/${ctx.req.file.filename}` 
    }
  }
})

// 上传用户头像
.post('/uploadUserIcon', uploadOne('/images/user-icons/'), async (ctx, next) => {
  let { host, post } = require('../../config/index').global
  ctx.body = {
    code: 0,
    message: '文章图片上传成功',
    data: {
      address: `http://${host}:${post}/images/user-icons/${ctx.req.file.filename}` 
    }
  }
})

// 上传轮播图片
.post('/uploadSlidesShowImage', uploadOne('/images/slides-show-images/'), async (ctx, next) => {
  let { host, post } = require('../../config/index').global
  ctx.body = {
    code: 0,
    message: '文章图片上传成功',
    data: {
      address: `http://${host}:${post}/images/slides-show-images/${ctx.req.file.filename}` 
    }
  }
})

module.exports = router